home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / gjboxx25.zip / MIDPLAY.CMD < prev    next >
OS/2 REXX Batch file  |  1996-05-13  |  31KB  |  1,034 lines

  1. /**************************************************************
  2.  *      *** MIDPLAY - Grin's Simple MIDi Jukeboxx ***
  3.  *
  4.  *                      version 2.50
  5.  *
  6.  *  Copyright 1995-96, Peter Gervai.  Free for personal use.
  7.  *
  8.  * Usage:
  9.  *   MidPlay [<file pattern>] [@<playlist name>] [<file pattern>] [switches]
  10.  * 
  11.  * Switches:  /V<vol>   Set global volume
  12.  *            /R<vol>   Set right volume (stereo only)
  13.  *            /L<vol>   Set left  volume (stereo only)
  14.  *            /S        Shuffle play - randomize musics
  15.  * Examples:
  16.  *   MidPlay
  17.  *     Plays all *.MID files in the current directory
  18.  *
  19.  *   MidPlay /S E:\TMP\MIDI\A*.MID M:\IDI\"C64 Evergreens"\*
  20.  *     Plays the given files of the given directory, shuffled
  21.  *
  22.  *   MidPlay TheSatan.Mid @hellish.list
  23.  *     Plays the Satan's song then all files in the playlist
  24.  ***************************************************************
  25.  *
  26.  * (This program eats up very few CPU cycles. You can use it in the
  27.  * background.)
  28.  *
  29.  * License
  30.  *  If you are using the program in a non-commercial environment
  31.  *  then you're free to use, copy, or delete it. You must not sell it.
  32.  *  You can include it on CDRoms or in shareware catalogs.
  33.  *  Commercial users should contact me about the license fees.
  34.  *  
  35.  *  This program is copyrighted material of Peter Gervai, Hungary.
  36.  *  Please do not distribute modified versions without my approval. Thanks!
  37.  *
  38.  *
  39.  *
  40.  *  PLEASE tell me about your ideas about the program!
  41.  *
  42.  *
  43.  * History:
  44.  *   1.0  - Release the in-house version
  45.  *   1.1  - Pause song, bad MIDi file handling
  46.  *   1.2  - Error control, restart
  47.  *   1.3  - Handle HPFS extreme filenames (space, comma, etc in names)
  48.  *   1.99 - Seeking
  49.  *   2.0  - New interface ;-) : direct keyboard, pos display, volumes
  50.  *   2.1  - New interface strikes back: borders, volume, buttons'n'boxes
  51.  *   2.2  - More paths on commandline (the song counter cheats, though!)
  52.  *   2.21 - Use the more general "sequencer" device instead of "sequencerNN"
  53.  *   2.3  - Don't close sequencer instance. This helps playing type0
  54.  *          MIDis without exact channel programming (uses the already loaded
  55.  *          intruments... <sigh>)
  56.  *        - The INIT midi created
  57.  *        - inet email address changed :(
  58.  *   2.31 - volume won't change to 100% after play a new song
  59.  *        - volume can be preset [now only in the source]
  60.  *        - The INIT midi is searched where MidPlay resides. Hopefully. :)
  61.  *        - nasty logical error fixed when multiple filenames on
  62.  *          commandline were with spaces in them. It wasn't my fault... ;->
  63.  *   2.40 - shuffle play
  64.  *        - fix song counter to count every file 
  65.  *        - using command line params for preset volume (are you happy, Costas? :))
  66.  *        - email changed again.... hrrgh
  67.  *   2.50 - colors! [It looks almost like a REAL MIDiplayer... ;-)]
  68.  *        - fixed B_Plain for volbars and percent bars :)
  69.  *        - using playlists! you can store favourite midis from all over your
  70.  *          harddisk. Use full paths where needed. One name per line.
  71.  *        - some minor fix
  72.  *
  73.  * TODO:
  74.  *        - nicer error messages (eg. ~~~INI~~~ file not found, bad midi)
  75.  *          (hmm, well, I like it this way :->)
  76.  *        - ? your ideas ?
  77.  *
  78.  * Author
  79.  *  Peter "Grin" Gervai, 2:370/15@fidonet, 81:436/3@OS2Net,
  80.  *                       grin@lifeforce.fido.hu
  81.  */
  82. call RxFuncAdd "SysFileTree", "RexxUtil", "SysFileTree"
  83. call RxFuncAdd "SysSleep",    "RexxUtil", "SysSleep"
  84. call RxFuncAdd "SysCls",      "RexxUtil", "SysCls"
  85. call RxFuncAdd "SysGetKey",   "RexxUtil", "SysGetKey"
  86. call RxFuncAdd "SysCurPos",   "RexxUtil", "SysCurPos"
  87.  
  88. /* Record error and get back to work*/
  89. Call on failure name error1
  90. Call on halt name error2
  91. /*signal on syntax name error3*/
  92.  
  93.  
  94. /*******************************************************************
  95.  * Character Schemes
  96.  *
  97.  * Usually you are supposed to use the PC charset, but 
  98.  * some national codepage just fucks up the box chars...
  99.  *
  100.  */
  101. /*         12345678901234567       graph schemes for tables and buttons */
  102. B_Plain = "+-+|+-+| ++++#*<>"
  103. B_Pc    = "┌─┐│└─┘│ ├┤┬┴▒░"
  104.  
  105. /*******************************************************************
  106.  * Color Schemes
  107.  *
  108.  *      
  109.  *   0(8) =black  1(9) =red   2(10)=green   3(11)=brown  4(12)=blue 
  110.  *   5(13)=purple 6(14)=cyan  7(15)=white  
  111.  */
  112.  /* 1 background, 2 statusline, 3 counter, 4 songbar, 5 totalsec, 6 secbar,
  113.   * 7 actualsec, 8 total header, 9 volbar, 10 volheader, 
  114.   * 11 buttonborder, 12 buttonchar, 13 buttonshadow, 14 pausebg, 
  115.   * 15 errorcol */
  116.  
  117. /* My colours. Cold and blue of course! */
  118. C_Grin  = '15,4 14,4 7,4 15,4 6,4 12,4',
  119.           '11,4 14,4 13,4 6,4',
  120.           '14,4 15,4 8,0 0,4',
  121.           '9,0'
  122.  
  123. /* This set is called: "Ouch!" :) */
  124. C_Test  = '15,4 14,5 1,6 15,2 3,7 4,7',
  125.           '0,4 13,1 13,4 6,4',
  126.           '15,1 0,2 8,0 14,7',
  127.           '9,0'
  128.  
  129. ProgVersion = "2.50"
  130.  
  131. /*******************************************************************
  132.  *
  133.  * You can change these
  134.  *
  135.  */
  136.  
  137. /* we use PC characters to display graphics :) */
  138. styp = B_Pc
  139.  
  140. /* use my favourite color scheme :) */
  141. ctyp = C_Grin
  142.  
  143. /* use colors (if you set it to 0 you will get no ANSI colors at all) */
  144. C_UseColors = 1
  145.  
  146. /* use 90% as the starting volume [value: 0-100] */
  147. lvol = 90
  148. rvol = 90
  149.  
  150. /* verbose mode */
  151. VerboseMode = 1
  152.  
  153. /*
  154.  * ...do not change after that.
  155.  * 
  156.  *******************************************************************/
  157.  
  158. LastLeftVol  = -1
  159. LastRightVol = -1
  160. LastTotalsBar = -1
  161. StereoUnchecked = 1
  162.  
  163. shufflePlay = 0
  164.  
  165. initfilename = '~~init~~.mid'           /* this IS case sensitive! */
  166. file.0 = 0
  167.  
  168. globals = 'SupportStereoVol LastTotalsBar LastPercent LastLeftVol',
  169.           'LastRightVol C_UseColors colors. oldchar oldbg VerboseMode',
  170.           'styp ctyp lvol rvol'
  171.  
  172. /* Send commands to OS/2 command processor.  */
  173. address cmd      
  174.  
  175. FILE=''
  176. Parse Arg pattern
  177.  
  178. parse source . . myself
  179. mypath = SubStr(myself,1,LastPos('\',myself))
  180.  
  181. if pattern=='' then pattern='*.MID'
  182.  
  183. Do while pattern \== ''
  184. /* first word --> pattern
  185.  * rest       --> restpattern
  186.  */
  187.   call ParseNextName
  188.   
  189.   select
  190.     when Left(pattern,1) = '/' then do
  191.     /* command line switch */
  192.       swChar = Translate(SubStr(pattern,2,1))
  193.       swArg  = SubStr(pattern,3)
  194.       select
  195.         when swChar = 'R' then do
  196.         /* right volume */
  197.           if swArg<0 | swArg>100 then call ArgError 'Illegal volume' swArg
  198.           rvol = swArg
  199.         end
  200.         
  201.         when swChar = 'L' then do
  202.         /* left volume */
  203.           if swArg<0 | swArg>100 then call ArgError 'Illegal volume' swArg
  204.           lvol = swArg
  205.         end
  206.         
  207.         when swChar = 'V' then do
  208.         /* global volume (have priority) */
  209.           if swArg<0 | swArg>100 then call ArgError 'Illegal volume' swArg
  210.           lvol = swArg
  211.           rvol = swArg
  212.         end
  213.         
  214.         when swChar = 'S' then do
  215.         /* set shuffle play */
  216.           shufflePlay = 1
  217.         end
  218.         
  219.         when swChar = 'H' | swChar = '?' then do
  220.         /* help */
  221.           Call ShowHelp
  222.           exit 1;
  223.         end
  224.         otherwise call ArgError 'Unknown switch' swChar
  225.       end
  226.     end
  227.     
  228.     when Left(pattern,1) = '@' then do
  229.       /* playlists */
  230.       if VerboseMode then say 'Processing playlist' SubStr(pattern,2)'...'
  231.       call ReadPlaylist SubStr(pattern,2)
  232.     end
  233.     
  234.     otherwise do
  235.     /* filename pattern */
  236.       if VerboseMode then say 'Scanning pattern' pattern'...'
  237.       CALL SysFileTree pattern,'filebuf','F'
  238.     
  239.       if filebuf.0 = 0 then say 'Warning, no MIDi found at' pattern'!'
  240.       /*
  241.        * append filebuf. to file.
  242.        */
  243.       counter = file.0
  244.       do i=1 to filebuf.0
  245.         if pos(initfilename,filebuf.i)=0 then do
  246.           /* I don't want to listen the INIT twice... */
  247.           counter = counter + 1
  248.           file.counter = filebuf.i
  249.         end
  250.       end
  251.       file.0 = counter
  252.     end
  253.   end
  254.   
  255.   /* read the rest of the command l